# Contents: Song.rb
# Purpose: To provide a Song Data object
# Status: Complete

require 'Make_Hash'

class Song
	def initialize( filepath,artist,album,title,duration,hash,playcount,rating,last_played)
		@artist = artist
		@album = album
		@title = title
		@duration = duration
		if (FileTest.exist?(filepath))
			@hash = Song.make_hash(filepath)
		else
			@hash = hash
		end
		@playcount = playcount
		@rating = rating
		@last_played = last_played
		@filepath = filepath
	end

	def filepath
		@filepath
	end
	
	def artist
		@artist
	end
  
	def album
		@album
	end
  
	def title
		@title
	end
  
	def duration
		@duration
	end
  
	def hash
		@hash
	end
  
	def playcount
		@playcount
	end
  
	def increment_playcount(pc)
		if @playcount == nil then
			@playcount = pc
		else
			@playcount = @playcount.to_i + pc
		end
	end
   
	def rating
		@rating
	end
  
	def set_rating (r)
		@rating=r
	end
  
	def last_played
		@last_played
	end
   
	def set_last_played(lp)
		@last_played = lp
	end
  
	def to_s
		return "Song Info: \r\n\tArtist: #{artist}\r\n\tAlbum: #{@album}\r\n\tTitle: #{@title}\r\n\tPlay Count: #{playcount}\r\n\tRating: #{rating}"
	end
  
  def to_response
    return  "\"#{filepath}\" \"#{artist}\" \"#{album}\" \"#{title}\" \"#{duration}\" \"#{hash}\" \"#{playcount}\" \"#{rating}\" \"#{last_played}\""
  end
end
